package at.fhooe.stefanirndorfer.update;

import java.util.LinkedList;

public class SimpleUpdateManager implements Updateable {

	private LinkedList<Updateable> m_objects;

	public SimpleUpdateManager() {
		m_objects = new LinkedList<Updateable>();
	}

	/**
	 * Registers an updateable. Objects are updated in the order in which they
	 * have been registered.
	 * Attention: duplicate entries allowed!
	 * 
	 * @param obj
	 *            Object to be updated
	 */
	public void register(Updateable obj) {
		if (m_objects==null){
			m_objects = new LinkedList<Updateable>();
		}
		m_objects.add(obj);
	}

	/**
	 * Unregisters the first occurence of obj
	 * 
	 * @param obj
	 *            Object to be unregistered
	 * @return true, if the object was registered
	 */
	public boolean unregister(Updateable obj) {
		m_objects=null;
		return true;
	}

	@Override
	public void update(double dt) {
		if (m_objects!=null){
			for (Updateable obj : m_objects)
				obj.update(dt);
		}
	}

}
